﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartSpace.Core;
using SsTool.Core.Windows;

namespace SsTool.Core
{
    /// <summary>
    /// Interaction logic for ThemeListPage.xaml
    /// </summary>
    public partial class ThemeListPage : Page
    {
        public ThemeListPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ThemeListPage_Loaded);
        }

        void ThemeListPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void LoadDatas()
        {
            ICoreService service = App.Get<ICoreService>();
            _ctlGrid.ItemsSource = service.GetThemes();
        }

        private void _ctlBtnCreate_Click(object sender, RoutedEventArgs e)
        {
            ThemeWindow window = new ThemeWindow();
            if (window.ShowDialog() == true)
            {
                LoadDatas();
            }
        }

        private void _ctlBtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            Theme model = _ctlGrid.SelectedItem as Theme;
            if (model != null)
            {
                ThemeWindow window = new ThemeWindow(model);
                if (window.ShowDialog() == true)
                {
                    LoadDatas();
                }
            }
            else
            {
                MessageBox.Show("请选择一个主题!");
            }
        }

        private void _ctlBtnDelete_Click(object sender, RoutedEventArgs e)
        {
            //User selectedUser = _ctlGridUser.SelectedItem as User;
            //if (selectedUser != null)
            //{
            //    if (MessageBox.Show("你是否要删除用户[" + selectedUser.Name + "]?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            //    {
            //        ICoreService coreService = App.Get<ICoreService>();
            //        if (coreService.RemoveUser(selectedUser))
            //        {
            //            LoadDatas();
            //        }
            //        else
            //        {
            //            MessageBox.Show("删除失败!");
            //        }
            //    }
            //}
            //else
            //{
            //    MessageBox.Show("请选择一个用户!");
            //}
        }
    }
}
